package com.avengers.common.bean;

import com.avengers.core.kit.DateKit;
import com.avengers.core.kit.RegexKit;
import com.avengers.core.kit.StringKit;

import java.util.Date;

/**
 * @author yu.wang
 * @since 2024/12/9 16:47
 **/
public class HttpResponse {
    private final Integer httpCode;
    private final String httpMessage;
    private final String sourceBody;

    private Date responseTime;

    public HttpResponse(Integer httpCode, String httpMessage, String body) {
        this.httpCode = httpCode;
        this.httpMessage = httpMessage;
        this.sourceBody = body;
    }

    public Integer getHttpCode() {
        return httpCode;
    }

    public String getHttpMessage() {
        return httpMessage;
    }

    public String getSourceBody() {
        return sourceBody;
    }

    public Date getResponseTime() {
        return responseTime;
    }

    public void setResponseTime(Date responseTime) {
        this.responseTime = responseTime;
    }

    @Override
    public String toString() {
        return (null == responseTime ? "" : (DateKit.toStr(responseTime, RegexKit.DATE_TIME_FORMAT_WITHOUT_SYMBOL) + "|"))
                + (null == httpCode ? "0" : httpCode)
                + (StringKit.isBlank(httpMessage) ? "" : "|" + httpMessage) + ":" + sourceBody;
    }
}
